<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Model\Admin\Cat;
class CatController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
      $data1 = DB::table('cat')->get();
      $data2 = Cat::tree($data1);
      return view('admin.cat_list',['cat'=>$data2]);
       
       
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
      $data1 = DB::table('cat')->get();
      $data2 = Cat::tree($data1);
      return view('admin.cat_create',['cat'=>$data2]);

    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
        $user = DB::table('user')->where('id',$id)->first();
        return view('admin.user_show',['user'=>$user]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //

       return view('admin.cat_edit',['id'=>$id]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        DB::table('cat')->where('id',$id)->update(['cat_name'=>$request->name]);
    }

    public function add(Request $request){
        $data['cat_name'] = $request->name;
        $data['pid']      = $request->pid;
        DB::table('cat')->insert($data);
    }
    //删除用户
    public function del($id)
    {
       Cat::dele($id);
       
    }
  
 
}